home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4141 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.5 KB  |  55 lines

  1. Path: newspost1.alt.net!usenet
  2. From: walth@netcom.com (Walt Howard)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Two way communication between objects
  5. Date: Sun, 28 Jan 1996 12:19:28 GMT
  6. Organization: AltNet - Affordable Usenet Access - http://www.alt.net
  7. Message-ID: <4efpkq$elb@tofu.alt.net>
  8. References: <310ACCE2.2600@werple.mira.net.au>
  9. Reply-To: walth@netcom.com
  10. X-Newsreader: Forte Agent .99c/32.126
  11.  
  12. On Sun, 28 Jan 1996 11:09:54 +1000, Ross Forder
  13. <erosco@werple.mira.net.au> wrote:
  14.  
  15. >I have to apologise what what is probably a stupid question but I'm only
  16. >a beginner at some of this stuff.
  17. >
  18. >I am trying to write a VERY simple client and server set of objects. I 
  19. >would like to client to register with the server at ctor time and have 
  20. >the server know about the client by saving a pointer to the client 
  21. >so he can callback to a method called say 'event'. 
  22. >
  23. >The problem is the fact that they will both need a pointer to each other 
  24. >and this seems impossible using strong typing. Is there a simple 'object 
  25. >oriented' way to do this?
  26.  
  27. You can declare a class without defining it. In this example class A
  28. is declared but it's definition occurs later.
  29.  
  30. class A;
  31.  
  32. class B
  33. {
  34.     A* PointerToA;
  35. };
  36.  
  37. class A
  38. {
  39.     B* PointerToB;
  40. };
  41.  
  42. That solves the problem about "pointers to each other" if that indeed
  43. was your problem.
  44. >
  45. >I have been able to make this work by having the server only know about 
  46. >a parent class of the client (say eventhandler) but this is still not a 
  47. >bulletproof solution.
  48. >
  49. >Can someone set me straight?
  50. >
  51. >Thanks
  52. >Ross Forder
  53.  
  54.  
  55.